package com.lfg.leetcode.leetcode100;


import java.util.HashMap;
import java.util.Map;

public class No137singleNumber {

    public static void main(String[] args) {
        System.out.println(singleNumber(new int[]{1, 2, 3, 6, 1, 2, 3, 1, 2, 3}));
    }

    public static int singleNumber(int[] nums) {
        Map<Integer, Integer> data = new HashMap<Integer, Integer>(nums.length);
        for (int i : nums) {
            int ret = data.getOrDefault(i, 0);
            data.put(i, ret + 1);
        }

        for (Map.Entry<Integer, Integer> entry : data.entrySet()) {
            if (entry.getValue() == 1) {
                return entry.getKey();
            }
        }
        return -1;
    }
}
